package deprecated;

import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.Scanner;
import towerDefense.libraries.TDLibraries;
import towerDefense.maps.MapException;
import towerDefense.maps.tiles.TerrainTile;
import towerDefense.maps.util.LibraryException;
import util.libraries.SubDirectoryLibrary;
import util.qualitycontainers.qualities.generics.NameQ;


/**
 * Used to create a map of terrainTiles from a specifically formatted map
 * blueprint document
 * 
 * @author Julian
 */
public class MapFactory
{

    private static final String LINE_DELIMITER = "\\|";
    private static final String TILE_DELIMITER = "\\s+";


    public static int[][] createMapFromFile (File doc)
    {
        try
        {
            Scanner scan = new Scanner(doc);

            int[][] map =
                new int[rows[0].split(TILE_DELIMITER).length][rows.length];
            for (int j = 0; j < map[0].length; j++)
            {
                String[] names = rows[j].split(TILE_DELIMITER);
                for (int i = 0; i < names.length; i++)
                {
                    map[i][j] =
                        TDLibraries.TerrainLibrary.getIDByName(names[i]);
                }
            }
            return map;
        }
        catch (Exception e)
        {
            throw new MapException(MapException.BAD_FORMAT);
        }

    }


    private static String[] splitBlueprintToRows (File doc)
        throws FileNotFoundException
    {

        Scanner scan = new Scanner(doc);
        StringBuilder st = new StringBuilder();
        while (scan.hasNextLine())
        {
            st.append(scan.nextLine());
        }
        String[] rows = st.toString().split(LINE_DELIMITER);

        return rows;
    }

}
